import { reactive, computed } from "vue";
import { onPullDownRefresh, onReachBottom, onReady, onShow } from "@dcloudio/uni-app";

import { useCool, useStore } from "/@/cool";
const { router, service, mitt } = useCool();
const { user } = useStore()

const payCallMixin = (value?: any | {
    isInit: true
}) => {

    function init() {
        const { payStatus } = router.query

        if (payStatus === undefined || payStatus === null) {
            return false
        }

        if (payStatus == 0 || payStatus == -1) {
            console.info("router", router)
            console.info("getCurrentPages()", getCurrentPages())
            // router.back()
            // uni.navigateBack({
            //     delta: 1
            // })
            return false
        }

        let routerKey = 'mess'
        if ((router.path?.indexOf('/pages/mess/') ?? -1) > -1) {
            routerKey = 'mess'
        } else if ((router.path?.indexOf('/pages/fitness/') ?? -1) > -1) {
            routerKey = 'fitness'
        } else if ((router.path?.indexOf('/pages/farm/') ?? -1) > -1) {
            routerKey = 'farm'
        } else if ((router.path?.indexOf('/pages/activity/') ?? -1) > -1) {
            routerKey = 'activity'
        } else if ((router.path?.indexOf('/pages/integral/') ?? -1) > -1) {
            routerKey = 'integral'
        }

        const url = `/pages/${routerKey}/order`

        uni.showToast({
            title: '支付成功！',
            icon: 'success',
            mask: true,
            duration: 1000,
            complete: function () {
                router.push({
                    path: url,
                    data: {},
                    mode: "redirectTo"
                });
            }
        })
    }

    onReady(() => {
        init()
    })

    return {
        init,
    };
}

export default payCallMixin